from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

class AppUpdateModel(db.Model):
    __tablename__ = 'app_update'

    id = db.Column(db.Integer, primary_key=True)
    has_update = db.Column(db.Integer, nullable=False)
    is_force = db.Column(db.Integer, default=0)
    is_ignorable = db.Column(db.Integer, default=0)
    version_code = db.Column(db.Integer, nullable=False)
    version_name = db.Column(db.String(255), nullable=False)
    update_content = db.Column(db.Text, nullable=False)
    download_url = db.Column(db.String(255), nullable=False)
    apk_size = db.Column(db.Integer, default=0)
    apk_md5 = db.Column(db.String(255), default='')
    create_time = db.Column(db.DateTime, default=db.func.current_timestamp(), comment='创建时间')

    def to_dict(self):
        return {
            'id': self.id,
            'hasUpdate': self.has_update == 1,
            'isForce': self.is_force == 1,
            'isIgnorable': self.is_ignorable == 1,
            'versionCode': self.version_code,
            'versionName': self.version_name,
            'updateContent': self.update_content,
            'downloadUrl': self.download_url,
            'apkZize': self.apk_size,
            'apkMd5': self.apk_md5,
            'createTime': self.create_time,
        }